from app import app, request, jsonify,basedir
import random,string
#保存图片
class save_img(object):
    #生成随机数 防止图片名重复
    ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 16))
    def __init__(self,img_files,img_url):
        self.img_files = img_files  #图片文件
        self.img_url = img_url or '/static/img/upload/' #图片保存地址

    def save(self):
        path = basedir + self.img_url
        imgName = self.ran_str + self.img_files.filename
        file_path = path + imgName
        self.img_files.save(file_path)
        return self.img_url + imgName

